home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mint110s / trans.c < prev    next >
C/C++ Source or Header  |  1993-09-08  |  5KB  |  256 lines

  1. /*
  2.  * translation routines; sometimes we pass data on
  3.  * through directly (asm syntax->asm syntax, with
  4.  * some macro expansion), and other times we also
  5.  * do asm syntax->gas syntax translation
  6.  */
  7.  
  8. #include "asmtrans.h"
  9.  
  10. int syntax = GAS;
  11.  
  12. char *
  13. immediate(op)
  14.     char *op;
  15. {
  16.     return concat("#", op);
  17. }
  18.  
  19. char *
  20. indirect(op)
  21.     char *op;
  22. {
  23.     if (syntax == GAS) {
  24.         return concat(op, "@");
  25.     } else {
  26.         return concat3("(", op, ")");
  27.     }
  28. }
  29.  
  30. char *
  31. postinc(op)
  32.     char *op;
  33. {
  34.     if (syntax == GAS) {
  35.         return concat(op, "@+");
  36.     } else {
  37.         return concat3("(", op, ")+");
  38.     }
  39. }
  40.  
  41. char *
  42. predec(op)
  43.     char *op;
  44. {
  45.     if (syntax == GAS) {
  46.         return concat(op, "@-");
  47.     } else {
  48.         return concat3("-(", op, ")");
  49.     }
  50. }
  51.  
  52. char *
  53. indexed(op1, op2)
  54.     char *op1, *op2;
  55. {
  56.     if (syntax == GAS) {
  57.         return concat4(op2, "@(", op1, ")");
  58.     } else {
  59.         return concat4(op1, "(", op2, ")");
  60.     }
  61. }
  62.  
  63. char *
  64. sizedop(op, size)
  65.     char *op, *size;
  66. {
  67.     if (syntax == GAS) {
  68.         return changesiz(concat(op, size));
  69.     } else {
  70.         return concat4("(", op, ")", size);
  71.     }
  72. }
  73.  
  74. char *
  75. twoindex(disp, base, index)
  76.     char *disp, *base, *index;
  77. {
  78.     if (syntax == GAS) {
  79.         return concat6(base, "@(", disp, ",", changesiz2(index), ")");
  80.     } else {
  81.         return concat6(disp, "(", base, ",", index, ")");
  82.     }
  83. }
  84.  
  85. char *
  86. bitfield(op1, op2, op3)
  87.     char *op1, *op2, *op3;
  88. {
  89.     if (syntax == GAS) {
  90.         return concat6(op1, "{#", op2, ":#", op3, "}");
  91.     } else {
  92.         return concat6(op1, "{", op2, ":", op3, "}");
  93.     }
  94. }
  95.  
  96. char *
  97. postindex(bd, an , index, od)
  98.     char *bd, *an, *index , *od;
  99. {
  100.     if (syntax == GAS) {
  101.         return concat8(an, "@(", bd, ")@(", od, ",", changesiz2(index), ")");
  102.     } else {
  103.         return concat9("([",an, ",", bd, "],", index, ",", od ,")");
  104.     }
  105. }
  106.  
  107. char *
  108. postindex0(bd)
  109.     char *bd;
  110. {
  111.     if (syntax == GAS) {
  112.         return concat3("@(", bd, ")@()");
  113.     } else {
  114.         return concat3("([", bd, "])");
  115.     }
  116. }
  117.  
  118. char *
  119. postindex1(bd,od)
  120.     char *bd, *od;
  121. {
  122.     if (syntax == GAS) {
  123.         return concat5("@(", bd, ")@(", od, ")");
  124.     } else {
  125.         return concat5("([", bd, "],", od, ")");
  126.     }
  127. }
  128.  
  129. char *
  130. preindex(bd, an , index, od)
  131.     char *bd, *an, *index , *od;
  132. {
  133.     if (syntax == GAS) {
  134.         return concat8(an, "@(", bd, ",", changesiz2(index), ")@(", od, ")");
  135.     } else {
  136.         return concat9("([",an, ",", bd, ",", index, "],", od, ")");
  137.     }
  138. }
  139.  
  140. char *
  141. do_ops(label, opcode, space, operand)
  142.     char *label, *opcode, *space, *operand;
  143. {
  144.     static char temp[LINSIZ];
  145.     static char optemp[40];
  146.     char *to, *from;
  147.     char c;
  148.  
  149.     if (syntax == GAS) {
  150.         if (!strcmp(opcode, "ds.l")) {
  151.         strcpy(temp, "\t.even\n\t.comm");
  152.         strcat(temp, space);
  153.         strcat(temp, label);
  154.         strcat(temp, ",");
  155.         strcat(temp, "4*");
  156.         strcat(temp, operand);
  157.         return strdup(temp);
  158.         } else if (!strcmp(opcode, "ds.w")) {
  159.         strcpy(temp, "\t.even\n\t.comm");
  160.         strcat(temp, space);
  161.         strcat(temp, label);
  162.         strcat(temp, ",");
  163.         strcat(temp, "2*");
  164.         strcat(temp, operand);
  165.         return strdup(temp);
  166.         } else if (!strcmp(opcode, "ds.b")) {
  167.         strcpy(temp, "\t.comm");
  168.         strcat(temp, space);
  169.         strcat(temp, label);
  170.         strcat(temp, ",");
  171.         strcat(temp, operand);
  172.         return strdup(temp);
  173.         } else {
  174.         to = optemp;
  175.         from = opcode;
  176.         for(;;) {
  177.             c = *from++;
  178.             if (!c) break;
  179.     /* change 'foo.b' -> 'foob' */
  180.     /* special case: bra.s -> 'bra', since gas automatically
  181.      * selects offset sizes and since some gas's actually
  182.      * mess up if an explicit '.s' is given
  183.      */
  184.             if (c == '.' && *from && from[1] == 0) {
  185.                 if (*from == 's') from++;
  186.                 continue;
  187.             }
  188.             *to++ = c;
  189.         }
  190.         *to = 0;
  191.         opcode = optemp;
  192.         }
  193.     }
  194.  
  195.     to = temp;
  196.  
  197.     if (*label) {
  198.         int colonseen = 0;
  199.         char c;
  200.  
  201.         for (from = label; (c = *from++) != 0;) {
  202.             if (c == ':') colonseen = 1;
  203.             *to++ = c;
  204.         }
  205. /* gas labels must have a ':' after them */
  206.         if (!colonseen && syntax == GAS)
  207.             *to++ = ':';
  208.     }
  209.  
  210.     *to++ = '\t';
  211.     strcpy(to, opcode);
  212.     strcat(temp, space);
  213.     strcat(temp, operand);
  214.     return strdup(temp);
  215. }
  216.  
  217. char *
  218. changesiz(op)
  219.     char *op;
  220. {
  221.     char *r = op;
  222.  
  223.     if (syntax != GAS) return op;
  224.  
  225.     while (*op) {
  226.         if (*op == '.') *op = ':';
  227.         op++;
  228.     }
  229.     return r;
  230. }
  231.  
  232. char *
  233. changesiz2(op)        /* rw: hack for scaled index    */
  234.     char *op;
  235. {
  236.     char *r = op;
  237.  
  238.     if (syntax != GAS) return op;
  239.  
  240.     while (*op) {
  241.         if (*op == '.' || *op == '*' ) *op = ':';
  242.         op++;
  243.     }
  244.     return r;
  245. }
  246.  
  247. char *
  248. hexop(op)
  249.     char *op;
  250. {
  251.     if (syntax == GAS)
  252.         return concat("0x", op);
  253.     else
  254.         return concat("$", op);
  255. }
  256.